/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.result;


public class DatabaseResultEntry implements Comparable<DatabaseResultEntry> {
	public int type = -1;
	public String database = "";
	public String host = "";
	public String password = "";
	public int port = 3306;
	public String table = "";
	public int dbType = 1;
	public String user = "";
	public int expire = -1;

	public DatabaseResultEntry() {

	}

	public DatabaseResultEntry(int type, String host, String database,
			String table, String user, String password) {
		this.host = host;
		this.user = user;
		this.password = password;
		this.table = table;
		this.type = type;
	}

	public DatabaseResultEntry(int type, String host, String database,
			String table, String user, String password, int dbType, int port,
			String tableSQL) {
		this.host = host;
		this.user = user;
		this.password = password;
		this.table = table;
		this.type = type;
		this.port = port;
		this.dbType = type;
	}

	public int compareTo(DatabaseResultEntry dbre) {

		if (dbre.host.compareTo(host) != 0)
			return -1;
		if (dbre.database.compareTo(database) != 0)
			return -1;
		if (dbre.password.compareTo(password) != 0)
			return -1;
		if (dbre.port != port)
			return -1;
		if (dbre.table.compareTo(table) != 0)
			return -1;
		if (dbre.type != type)
			return -1;
		if (dbre.dbType != dbType)
			return -1;
		if (dbre.user.compareTo(user) != 0)
			return -1;
		return 0;
	}

	public String toXML() {
		String temp = "<DatabaseResultEntry";
		temp += " type=\"" + type + "\"";
		temp += " host=\"" + host + "\"";
		temp += " database=\"" + database + "\"";
		temp += " table=\"" + table + "\"";
		temp += " port=\"" + port + "\"";
		temp += " user=\"" + user + "\"";
		temp += " password=\"" + password + "\"";
		if (expire > 0) {
			temp += " expire=\"" + expire + "\"";
		}

		if (dbType == 1)
			temp += " dbType=\"mysql\"";
		temp += "/>";
		return temp;
	}

}
